create or alter procedure [Timesheet].[Add Work] @Client int, @Project int, @Hours decimal(10,4), @Date date as begin set nocount on; if @Date is null select @Date = getutcdate(); declare @Developer int; select @Developer = d.Id from [Timesheet].Developers d where d.[Database Principal] = database_principal_id(); if @Developer is null throw 50000, 'Your account is not properly configured. Please contact your project manager.', 0; if not exists ( select 1 from [Timesheet].[Assigned Developers] ad where ad.Client = @Client and ad.Project = @Project and ad.Developer = @Developer) throw 50000, 'You are not assigned to the specified project.', 0; if exists ( select 1 from [Timesheet].[Work] w where w.Client = @Client and w.Project = @Project and w.Developer = @Developer and w.[Date] = @Date) throw 50000, 'Work for the specified project and date has already been reported.', 0; insert into [Timesheet].Work([Client], [Project], [Developer], [Date], [Hours]) values (@Client, @Project, @Developer, @Date, @Hours); end GO